<template>
	<view>
		<view class="header">
			<input placeholder="请输入关键词" placeholder-class="placeholder" confirm-type="search" @confirm="Search" v-model="title" />
			<image :src="imgurl+'search.png'" @tap="Search"></image>
			<view class="right" @tap="Create">创建</view>
		</view>
		<view style="padding-top: 96rpx; box-sizing: border-box;">
			<view class="main-item" v-for="(item,index) in list" :key="index" @tap="QuesHallDetail(item.wenid, index)">
				<view class="item-top flex">
					<view class="top-left row">
						<text>{{item.namewenid}}</text>
					</view>
					<view class="top-right row">
						<span>{{item.darenshu != null ? item.darenshu : '0'}}</span>
						<text>答卷数量</text>
					</view>
				</view>
				<view class="flex" style="justify-content: space-between; margin: 10rpx 0;font-size: 28rpx;color: #666;">
					<view>共{{item.zongshu!=null ? item.zongshu: '0'}}题</view>
					<view class="top-center">
						<text>问卷类型：</text>
						<text style="color: #36A6FC;">{{item.type == 1 ? '调查':item.type == 2 ? '表单' : '投票'}}问卷</text>
					</view>
				</view>
				<view class="item-content">{{item.text ? item.text : ''}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "@/common/api.js";
	import {
		baseURL
	} from "@/common/http.js";
	import app from "../../App.vue"
	export default {
		data() {
			return {
				imgurl: "",
				title: "",
				page: 1,
				list: []
			};
		},
		methods: {
			//创建
			Create() {
				if (uni.getStorageSync('message') && uni.getStorageSync('message')[0].call) {
					uni.navigateTo({
						url: "../create/create"
					})
				} else {
					uni.showModal({
						title: '系统提示',
						content: '访客没有创建权限，请先登录小程序，并绑定手机号',
						confirmColor: '#209FFC',
						confirmText: '确定',
						cancelText: '取消',
						success: (res) => {
							if (res.confirm) {
								setTimeout(() => {
									uni.navigateTo({
										url: '../loginIndex/loginIndex'
									})
								}, 500)
							} else if (res.cancel) {}
						}
					})
				}
			},
			Search(e) {
				this.list = []
				this.List({
					api: 'wenpeg',
					shu: '',
					order: 'fadate desc',
					namewenid: this.title,
					table: 3,
					fa: 2
				})
			},
			QuesHallDetail(wenid, index) {
				uni.navigateTo({
					url: "../questionHallDetial/questionHallDetial?wenid=" + wenid +'&index='+ index
				})
			},
			List(data) {
				api.quesList(data).then(res => {
					if (res.code == 200) {
						if(this.page == 1){
							this.list = res.date
						} else {
							this.list = this.list.concat(res.date)
						}
					} else if (res.code == 404) {
						uni.showToast({
							title: '没有更多了',
							icon: 'none',
							duration: 2000
						})
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad(options) {
			this.imgurl = app.globalData.imgurl
			this.page = 1
			this.List({
				api: 'wenpeg',
				shu: '',
				table: 3,
				fa: 2,
				order: 'fadate desc',
				page: this.page
			})
		},
		onReachBottom() {
			this.page++
			this.List({
				api: 'wenpeg',
				shu: '',
				order: 'fadate desc',
				table: 3,
				fa: 2,
				page: this.page
			})
		},
		onShow() {
			if(!uni.getStorageSync('message')) {
				uni.setNavigationBarTitle({
					title: '天天填'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F0F0F0;
		font-family: PingFang SC;
		font-weight: 500;
	}

	.placeholder {
		font-size: 30rpx;
		color: #999;
		font-weight: 500;
	}

	.header {
		width: 100%;
		background: #fff;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		position: fixed;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap: wrap;

		input {
			flex: 1;
			height: 60rpx;
			line-height: 60rpx;
			background: #F0F0F0;
			border-radius: 30rpx;
			padding-left: 7%;
			box-sizing: border-box;
			font-weight: normal;
			margin-right: 20rpx;
		}

		image {
			width: 50rpx;
			height: 50rpx;
			position: absolute;
			left: 5%;
			top: 30rpx
		}
		
		.right {
			width: 100rpx;
			height: 60rpx;
			background: #209FFC;
			border-radius: 30rpx;
			color: #fff;
			line-height: 60rpx;
			text-align: center;
			
		}
	}

	.main-item {
		width: 710rpx;
		margin: 20rpx auto;
		background: #fff;
		padding: 15rpx 20rpx;
		box-sizing: border-box;
		border-radius: 15rpx;
		.item-top {
			justify-content: space-between;
			margin: 10rpx 0;

			.top-left {
				align-items: initial;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 3;
				overflow: hidden;
				flex: 1;
				margin-right: 30rpx;

				text {
					color: #333;
					font-size: 34rpx;
					font-weight: bold;
				}

				span {
					color: #666;
					font-size: 32rpx;
					margin-left: 10rpx;
				}
			}

			.top-right {
				text {
					color: #999;
					font-size: 24rpx;
				}

				span {
					color: #36A6FC;
					font-size: 36rpx;
				}
			}
		}
	}

	.item-content {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		overflow: hidden;
		color: #999;
		font-size: 24rpx;
		line-height: 30rpx;
	}
</style>
